package com.jweb.framework.core.util;
import java.lang.ref.SoftReference;

public abstract class AbstractSoftThreadLocal extends ThreadLocal<Object> {
	
	public final Object get()
	  {
	    return ((SoftA)super.get()).geta();
	  }

	  protected final Object initialValue() {
	    /*return new a(null);*/
		  return new SoftA();
	  }

	  protected abstract Object create();

	  protected void reset(Object paramObject)
	  {
	  }

	  private class SoftA
	  {
	    private SoftReference<Object> softR = null;

	    private SoftA() {  } 
	    
	    Object geta() { 
	    	if (this.softR == null) {
		        return getb();
		      }
		      Object obj = this.softR.get();
		      if (obj != null) {
		        AbstractSoftThreadLocal.this.reset(obj);
		        return obj ;
		      }
		      return getb();
	    }

	    private Object getb()
	    {
	      Object obj = AbstractSoftThreadLocal.this.create();
	      this.softR = new SoftReference(obj);
	      return obj;
	    }
	  }

}
